/**
 * Filename: PopListImageDir.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/17 15:09
 */
package com.github.postsanf.yinian.activity.pop;

import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.CommonAdapter;
import com.github.postsanf.yinian.bean.YNImageFloder;
import com.github.postsanf.yinian.utils.LocalViewHolder;

import java.util.List;

public class PopListImageDir extends BasePopupWindowForListView<YNImageFloder> {
    private ListView mListDir;

    public PopListImageDir(int width, int height,
                           List<YNImageFloder> datas, View convertView) {
        super(convertView, width, height, true, datas);
    }

    @Override
    public void initViews() {
        mListDir = (ListView) findViewById(R.id.lv_album_list_dir);
        mListDir.setAdapter(new CommonAdapter<YNImageFloder>(context, mDatas,
                R.layout.yn_album_list_dir_item, 0) {
            @Override
            public void convert(LocalViewHolder helper, YNImageFloder item, Boolean isFirst) {
                helper.setText(R.id.tv_album_dir_item_name, item.getName());
                helper.setImageByUrl(R.id.iv_album_dir_item_image,
                        item.getFirstImagePath());
                helper.setText(R.id.id_dir_item_count, "(" + item.getCount() + ")");
            }
        });
    }

    public interface OnImageDirSelected {
        void selected(YNImageFloder floder);
    }

    private OnImageDirSelected mImageDirSelected;

    public void setOnImageDirSelected(OnImageDirSelected mImageDirSelected) {
        this.mImageDirSelected = mImageDirSelected;
    }

    @Override
    public void initEvents() {
        mListDir.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                if (mImageDirSelected != null) {
                    mImageDirSelected.selected(mDatas.get(position));
                }
            }
        });
    }

    @Override
    public void init() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void beforeInitWeNeedSomeParams(Object... params) {
        // TODO Auto-generated method stub
    }

}
